package cn.new7as.cas5s.ui.slideshow;


import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.OnHttpListener;

import cn.new7as.cas5s.databinding.ActivityContactUsBinding;
import cn.new7as.cas5s.tool.util.Utils;
import cn.new7as.cas5s.ui.easy.netapi.HttpData;
import cn.new7as.cas5s.ui.easy.netapi.GetCusApi;
import cn.new7as.cas5s.ui.record.SendTypeActivity;


public class ContactUsActivity extends BaseActivity {


    private ActivityContactUsBinding binding;
    ClipboardManager mClipboardManager;

    @SuppressLint("MissingPermission")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityContactUsBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setop("Contact us");
        initV();

        mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

    }

    @Override
    public void initV() {
        super.initV();
        show();
        getorder();
        binding.verifyme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Utils.go(ContactUsActivity.this, SendTypeActivity.class);
            }
        });

        setcopy(binding.CustomerMail, binding.copymail);
        setcopy(binding.CustomerPhone, binding.copyphone);
    }

    void setcopy(TextView textView, ImageView imageView) {
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                copy(textView.getText().toString());
            }
        });

    }


    void copy(String s) {
        ClipData mClipData = ClipData.newPlainText("Simple text", s);

        mClipboardManager.setPrimaryClip(mClipData);


    }

    private void getorder() {
        EasyHttp.get(this)
                .api(new GetCusApi(getunique())).request(new OnHttpListener<HttpData<GetCusApi.CusData>>() {
                    @Override
                    public void onHttpSuccess(@NonNull HttpData<GetCusApi.CusData> result) {
                        binding.CustomerMail.setText(result.getResult().email.trim());
                        binding.CustomerPhone.setText(result.getResult().mobile.trim());
                        hide();
                    }

                    @Override
                    public void onHttpFail(@NonNull Throwable throwable) {
                        deal(throwable);
                    }
                });
    }


}